﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;
using ScheduleMaker.DB;
using ScheduleMaker.DB.CoreDAO;
using ScheduleMaker.ConfigManager;

namespace ScheduleMaker.DB
{
    public class Authenticator
    {
        private static bool loged = false;
        private static User logedUser = null;
        private static UserDAO userDAO;

        static Authenticator()
        {
            userDAO = DAOFactory.getUserDAO(ConfigManager.ConfigManager.getConfiguration().Type);
        }

        public static bool autenticate(string login, string password)
        {
            User user = userDAO.findByLogin(login);
            if (user != null)
            {
                if(user.Password.Equals(MD5Coder.encode(password)))
                {
                    loged = true;
                    logedUser = user;
                }
            }

            return loged;
        }

        public static User LogedUser 
        {
            get { return logedUser; }
        }

        public static string Level
        {
            get { return logedUser.Level.Name; }
        }

    }
}
